package cn.com.zzz.taskpk.tcpip;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import cn.bbs.ba.socket.BusCodeToBusBase;
import cn.com.zzz.taskpk.base.PKBusCodeToBus;

/**
 * 启动socket服务器(这是一个监听，要在web.xml中注册)
 * @author xieyong
 *
 */
public class ServiceLoader843 implements ServletContextListener{
	private SocketThread843 socketThread;
	
	public void contextDestroyed(ServletContextEvent e) {
			if(null!=socketThread && !socketThread.isInterrupted())
			{
				socketThread.closeSocketServer();
				socketThread.interrupt();
			}
	}

	public void contextInitialized(ServletContextEvent e) {
			ServletContext servletContext = e.getServletContext();
			String str=(String)servletContext.getAttribute("socketThreadIsRun");
			if(null==str)
			{
				if(null==socketThread)
				{
					servletContext.setAttribute("SocketThread843", "true");
					socketThread = new SocketThread843(null,servletContext);
					socketThread.start();
				}
			}
	}

}